<template>
  <div>
    <div class="app-box">
      <div class="attrTitle" >基本信息</div>
      <a-divider></a-divider>
       <j-form-container :disabled="true">

        <a-form-model ref="mainForm" :model="hteFile" >
          <a-row>
            <a-col :span="24">
              <a-form-model-item v-bind="{labelCol: {
              xs: { span: 24 },
              md: { span: 4 },
            },

            wrapperCol: {
              xs: { span: 24 },
              md: { span: 18 },
            }}" label="文件名称" tyle="width: 100%" prop="fileName">
                <a-textarea v-model="hteFile.fileName" :auto-size="true"/>
              </a-form-model-item>
            </a-col>
             <a-col :span="12">
              
               <a-form-model-item v-bind="formItemLayout" label="文件类别" tyle="width: 100%" prop="fileType">
                <a-input v-model="hteFile.fileTypeName"  placeholder="文件类别" />
                
              </a-form-model-item>
            </a-col>
            <a-col :span="12" v-if="parentId==2" >
              <a-form-model-item v-bind="formItemLayout" label="文件编号" tyle="width: 100%">
                <a-input v-model="hteFile.fileNo" disabled placeholder="自动生成" />
                
              </a-form-model-item>
            </a-col>
             <a-col :span="12" v-else>
              <a-form-model-item v-bind="formItemLayout" label="文件编号" tyle="width: 100%" prop="fileNo">
                <a-input v-model="hteFile.fileNo"  placeholder="" />
                
              </a-form-model-item>
            </a-col>
          </a-row>

          <a-row>
              <a-col :span="24" v-if="parentId!=2">
              <a-form-model-item v-bind="{labelCol: {
              xs: { span: 24 },
              md: { span: 4 },
            },

            wrapperCol: {
              xs: { span: 24 },
              md: { span: 18 },
            }}" label="关键词" tyle="width: 100%" prop="keywords">
                <a-textarea v-model="hteFile.keywords" :auto-size="true"/>
              </a-form-model-item>
            </a-col>
             <a-col :span="24" v-if="parentId!=2">
              <a-form-model-item v-bind="{labelCol: {
              xs: { span: 24 },
              md: { span: 4 },
            },

            wrapperCol: {
              xs: { span: 24 },
              md: { span: 18 },
            }}" label="文件用途" tyle="width: 100%" prop="purpose">
                <a-textarea v-model="hteFile.purpose" :auto-size="true" placeholder=""/>
              </a-form-model-item>
            </a-col>
          
            <a-col :span="12">
              <a-form-model-item v-bind="formItemLayout" label="版本号" tyle="width: 100%">
                <a-input v-model="hteFile.version" disabled placeholder="自动生成" />
              </a-form-model-item>
            </a-col>
             <a-col :span="12">
              <a-form-model-item v-bind="formItemLayout" label="创建人" tyle="width: 100%">
                <a-input v-model="hteFile.createUser" disabled placeholder="自动生成" />
              </a-form-model-item>
            </a-col>
              <a-col :span="12">
              <a-form-model-item v-bind="formItemLayout" label="发布人" tyle="width: 100%">
                <a-input v-model="hteFile.publishUser" disabled placeholder="自动生成" />
              </a-form-model-item>
            </a-col>
             <a-col :span="12">
              <a-form-model-item v-bind="formItemLayout" label="发布部门" tyle="width: 100%">
                <a-input v-model="hteFile.publishDept" disabled placeholder="自动生成" />
              </a-form-model-item>
            </a-col>
             <a-col :span="12">
              <a-form-model-item v-bind="formItemLayout" label="发布生效时间" tyle="width: 100%">
                <a-input v-model="hteFile.effectTime" disabled placeholder="自动生成" />
              </a-form-model-item>
            </a-col>
             <a-col :span="12">
              <a-form-model-item v-bind="formItemLayout" label="创建部门" tyle="width: 100%">
                <a-input v-model="hteFile.addDept" disabled placeholder="自动生成" />
              </a-form-model-item>
            </a-col>
          </a-row>
          <!-- <a-row>
            <a-col :span="24">
              <a-form-model-item
                prop="purpose"
                :labelCol="{ md: 4, xs: 24 }"
                :wrapperCol="{ md: 18, xs: 24 }"
                label="文件用途"
                style="width: 100%"
              >
                <a-textarea v-model="hteFile.purpose" />
              </a-form-model-item>
            </a-col>
          </a-row> -->
        </a-form-model>
       </j-form-container >
        <div class="attrTitle" >关键信息</div>
        <a-divider></a-divider>
        <div class="attr-box" v-show="classAttrList.length > 0">
            <libFileAttr v-if="parentId==2" ref="fileattr" :classAttrList="classAttrList" :formItemLayout="formItemLayout" :parentId="parentId" :formDisabled="true"></libFileAttr>
            <FileAttrNormal v-if="parentId==4"  ref="fileattr" :classAttrList="classAttrList" :formItemLayout="formItemLayout" :parentId="parentId" :formDisabled="true"></FileAttrNormal>
          <!-- <a-form-item
            v-bind="formItemLayout"
            class="attr-item"
            v-for="(item, key) in classAttrList"
            :key="key"
            :label="item.name"
          >
            {{ item.content }}
          </a-form-item> -->
        </div>
    </div>
  </div>
</template>

<script>
import { getAction } from '@/api/manage'
import moment from 'moment'
import LibFileAttr from '@/views/library/components/LibFileAttr'
import FileAttrNormal from '@/views/library/components/FileAttrNormal'
export default {
  components: {LibFileAttr,FileAttrNormal},
  props:{
    parentId: {
      type: String,
      default: null,
      
    },
  },
  data() {
    return {
      formItemLayout: {
        labelCol: {
          xs: { span: 18 },
          sm: { span: 8 },
        },
        wrapperCol: {
          xs: { span: 20 },
          sm: { span: 12 },
        },
      },
      hteFile: {},
      classAttrList: [],
      urls: {
        listAttr: '/lib/hteLibFile/attrs',
        getTreeList: '/lib/hteFileClass/getTreeList',
      },
      form: this.$form.createForm(this, { name: 'form' }),
      treeData:[]
    }
  },
  created() {

  },
  methods: {
   
    /**
     * 获取分类扩展属性
     */
    fetchClassAttr(classId, fileId, version) {
      if (this.hteFile.fileType) {
        let classId = this.hteFile.fileType
        getAction(this.urls.listAttr + '?classId=' + classId + '&fileId=' + fileId + '&version=' + version, {}).then(
          (res) => {
            if (res.success) {
              this.classAttrList = res.result.filter(item=>{
                return !!item.showInDetails
              })
            } else {
              this.$message.error('获取分类拓展属性错误')
            }
          }
        )
      } else {
        this.classAttrList = []
      }
    },

    setMain(hteFile) {
      this.hteFile = hteFile
      this.fetchClassAttr(this.hteFile.fileType, this.hteFile.id, this.hteFile.version)
    },
    setClassAttr(attrs) {
      this.classAttrList = attrs
    },
  },
}
</script>

<style>
.attr-box {
  width: 100%;
  /* display: flex;
  align-content: flex-start;
  flex-flow: row wrap; */
}

/* .attr-item {
  width: 50%;
  margin: 0;
  margin-bottom: 20px;
} */
.ant-form-item{
  margin-bottom: 5px !important;
}
.attrTitle {
  height: 40px;
  line-height: 40px;
  text-align: left;
  font-size: 20px;
  font-weight: bold;
  color: #000
}
</style>